﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using DflyingForum.Core.Framework;
using DflyingForum.Core.Repositories;
using System.Web.Security;

namespace Core.Web.Code.UI.Controls
{
    public partial class Login : BaseControl
    {
        protected TextBox txtUserName;
        protected TextBox txtPassword;
        protected CheckBox chkRememberMe;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string userName = txtUserName.Text.Trim();
            string password = txtPassword.Text.Trim();
            if (_bllUser.IsExistUser(userName, password))
            {
                _bllUser.SetLogCookie(userName, chkRememberMe.Checked);
                //UserReposity.RedirectFromLoginPage(userName, chkRememberMe.Checked);会覆盖掉原来写的cookie
                Response.Redirect(FormsAuthentication.GetRedirectUrl(userName, chkRememberMe.Checked));
            }
            else
            {
                DflyingJScript.Alert("登录失败！", this.Page);
                return;
            }
        }
    }
}